package com.javastudy.jdkfeature.jdk8;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

import static java.util.stream.Collectors.toList;


/**
 * Created by admin on 2017/5/6.
 */
public class FolderList {
    public static void main(String[] args){
        ListFolders();
        listFolder2();
    }
    private static void ListFolders(){
        List<File> files = new ArrayList<>();
        List<File> folders = new ArrayList<>();
        File[] filesInCurerentDir = new File("E:\\OpenSources").listFiles();
        for(File file : filesInCurerentDir) {
            File[] filesInSubDir = file.listFiles();
            if(filesInSubDir != null) {
                files.addAll(Arrays.asList(filesInSubDir));
                folders.add(file);
            } else {
                files.add(file);
            }
        }
        System.out.println("Count: " + files.size());
        System.out.println("Folder Count: " + folders.size());
    }

    private static void listFolder2(){
        List<File> files = Stream.of(new File("E:\\OpenSources").listFiles())
                .flatMap(file -> file.listFiles() == null ?
                        Stream.of(file) : Stream.of(file.listFiles()))
                .collect(toList());
        System.out.println("Count: " + files.size());

    }
}
